package com.epam.airlines;

import java.io.Serializable;
import java.util.Random;

public abstract class Aircraft implements Comparable<Aircraft>, Serializable {

	private static final long serialVersionUID = 1L;
	private int consumption;
	private int distance;
	private int flyingHoursTotal;
	private String id;
	private String name;
	private int numPass;
	private float tonnage;

	public Aircraft(String name, int numPass, float tonnage, int distance,
			int consumption, String id) {
		this.name = name;
		this.numPass = numPass;
		this.tonnage = tonnage;
		this.distance = distance;
		this.consumption = consumption;
		this.setId(id);
	}

	public int compareTo(Aircraft airplane) {
		return airplane.getDistance() - distance;
	};

	public int getConsumption() {
		return consumption;
	}

	public int getDistance() {
		return distance;
	}

	public int getFlyingHoursTotal() {
		return flyingHoursTotal;
	}

	public String getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public int getNumPass() {
		return numPass;
	}

	public float getTonnage() {
		return tonnage;
	}

	public void makeFlight() {
		Random rand = new Random();
		flyingHoursTotal += rand.nextInt(10);
	}

	public void setConsumption(int consumption) {
		this.consumption = consumption;
	}

	public void setDistance(int distance) {
		this.distance = distance;
	}

	public void setFlyingHoursTotal(int flyingHoursTotal) {
		this.flyingHoursTotal = flyingHoursTotal;
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setNumPass(int numPass) {
		this.numPass = numPass;
	}

	public void setTonnage(float tonnage) {
		this.tonnage = tonnage;
	}

	public abstract String toString();

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + consumption;
		result = prime * result + distance;
		result = prime * result + flyingHoursTotal;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + numPass;
		result = prime * result + Float.floatToIntBits(tonnage);
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Aircraft other = (Aircraft) obj;
		if (consumption != other.consumption)
			return false;
		if (distance != other.distance)
			return false;
		if (flyingHoursTotal != other.flyingHoursTotal)
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (numPass != other.numPass)
			return false;
		if (Float.floatToIntBits(tonnage) != Float
				.floatToIntBits(other.tonnage))
			return false;
		return true;
	}
}
